package be.idamf.flash.system;

import flash.utils.ByteArray;
import flash.system.ApplicationDomain;

class Memory {
	
	public static inline function select(byteArray:ByteArray):Void {
		ApplicationDomain.currentDomain.domainMemory = byteArray;
	}
	
	public static inline function readByte(address:UInt):UInt {
		return untyped __vmem_get__(0, address);
	}

	public static inline function readUI16(address:UInt):UInt {
		return untyped __vmem_get__(1, address);
	}

	public static inline function readI32(address:UInt):Int {
		return untyped __vmem_get__(2, address);
	}

	public static inline function readFloat(address:UInt):Float {
		return untyped __vmem_get__(3, address);
	}

	public static inline function readDouble(address:UInt):Float {
		return untyped __vmem_get__(4, address );
	}

	public static inline function writeByte(address:UInt, value:Int):Void {
		untyped __vmem_set__(0, address, value);
	}

	public static inline function writeI16(address:UInt, value:Int):Void {
		untyped __vmem_set__(1, address, value);
	}

	public static inline function writeI32(address:UInt, value:Int):Void {
		untyped __vmem_set__(2, address, value);
	}

	public static inline function writeFloat(address:UInt, value:Float):Void {
		untyped __vmem_set__(3, address, value);
	}

	public static inline function writeDouble(address:UInt, value:Float):Void {
		untyped __vmem_set__(4, address, value);
	}
	
	public static inline function signExtend1(value:Int):Int {
		return untyped __vmem_sign__(0, value);
	}

	public static inline function signExtend8(value:Int):Int {
		return untyped __vmem_sign__(1, value);
	}

	public static inline function signExtend16(value:Int):Int {
		return untyped __vmem_sign__(2, value);
	}
}